<template>
  <div class="container">
    <div>{{ "确认修改邮箱为" + params.email + "吗" }}</div>
    <div class="layui-btn" @click="submit">确认修改</div>
    <router-link to="/" class="layui-btn">返回首页</router-link>
  </div>
</template>
<script>
import { updateUserEmail } from '@/api/user';

export default {
  name: 'reset',
  data () {
    return {
      params: ''
    };
  },
  methods: {
    submit () {
      updateUserEmail(this.params).then(res => {
        if (res.code === 200) {
          setTimeout(() => {
            this.$store.commit('setUserInfo', {
              ...this.$store.state.userInfo,
              email: this.params.email
            });
            this.$router.push('/');
          }, 1000);
        }
      }).catch((err) => {
        this.$alert(err);
      });
    }
  },
  mounted () {
    const queryString = decodeURIComponent(window.location.href.replace(/.*\?/, ''));
    this.params = Object.fromEntries(queryString.split('&').map(item => item.split('=')));
  }
}
</script>
<style scoped lang="scss">
  
</style>